import Vue from 'vue'
import '@/plugins/axios'
import App from './App.vue'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);



router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆
    var id = window.sessionStorage.getItem('userId');
    console.log(id)
    if (id) { // 查询本地存储信息是否已经登陆
      next();
    } else {
      next({
        path: '/', // 未登录则跳转至login页面
        redirect: '/home' // 登陆成功后回到当前页面，这里传值给login页面，to.fullPath为当前点击的页面
      });
    }
  } else {
    next();
  }
})


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
